package com.zzq.my.jetpacks.jectpackapp.ui.act

import androidx.recyclerview.widget.ConcatAdapter
import by.kirich1409.viewbindingdelegate.viewBinding
import com.aisier.architecture.base.BaseActivity
import com.zzq.my.jetpacks.jectpackapp.R
import com.zzq.my.jetpacks.jectpackapp.adapter.ButtonAdapter
import com.zzq.my.jetpacks.jectpackapp.adapter.TextAdapter
import com.zzq.my.jetpacks.jectpackapp.databinding.ActivityConcatadapterBinding
import com.zzq.my.jetpacks.util.DividerItemUtils

/**
 * 描述：ConcatAdapter  使用
 * 作者：zhuangzeqin
 * 时间: 2022/1/19-14:05
 * 邮箱：zzq@eeepay.cn
 * 备注:
 */
class ConcatAdapterAct :BaseActivity(R.layout.activity_concatadapter){
    private val binding by viewBinding(ActivityConcatadapterBinding::bind)
    private lateinit var txtAdapter: TextAdapter
    private lateinit var btnAdapter:ButtonAdapter
    private lateinit var btnAdapter2:ButtonAdapter
    /**
     * 初始化数据
     */
    override fun initData() {
        val mutableListOf = mutableListOf<String>()//声明一个可变的集合mutableListOf
        val mutableListOf2 = mutableListOf<String>()//声明一个可变的集合mutableListOf
        txtAdapter = TextAdapter()
        btnAdapter = ButtonAdapter()
        btnAdapter2 = ButtonAdapter()
        for (i in 0..10)
        {
            mutableListOf.add("txt${i}")
            mutableListOf2.add("btn${i}")
        }
        txtAdapter.setList(mutableListOf)
        btnAdapter.setList(mutableListOf2)
        btnAdapter2.setList(mutableListOf2)
        //isolateViewTypes=true是用来隔离itemViewType的 每个 adapter 的 都会创建自己的 ViewHolder
        //isolateViewTypes=false，如果itemViewType相同，则使用同一个缓存池。
//        val config = ConcatAdapter.Config.Builder().setIsolateViewTypes(true).build()
        val concatAdapter = ConcatAdapter(btnAdapter,txtAdapter,btnAdapter2)
        binding.rvList.adapter = concatAdapter

    }

    /**
     * 初始化操作
     */
    override fun initView() {
        //添加自定义分割线：可自定义分割线高度和颜色
        binding.rvList.addItemDecoration(
//            DividerItemUtils.dividerItemDecorationTool(mContext)//默认的间隔线
            DividerItemUtils.dividerItemDecorationTool(
                mContext,
                drawId = R.drawable.divider_mileage
            )//自定义间隔线
        )
    }

    /**
     * 初始化点击事件操作
     */
    override fun eventOnClick() {

    }
}